home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6337 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  70 lines

  1. Path: lll-winken.llnl.gov!usenet
  2. From: Mark Spruiell <mes@llnl.gov>
  3. Newsgroups: comp.lang.c++
  4. Subject: SPARCompiler problem
  5. Date: Thu, 08 Feb 1996 15:28:05 -0800
  6. Organization: Lawrence Livermore National Laboratory
  7. Message-ID: <311A8705.41C6@llnl.gov>
  8. NNTP-Posting-Host: disaster.llnl.gov
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (X11; I; IRIX 5.2 IP22)
  13.  
  14. I've encountered a discrepancy between two C++ compilers.  I'm using
  15. both SPARCompiler C++ 4.0.1 on Solaris 2.4 and SGI C++ 3.2.1 on IRIX 5.2.
  16. The code below illustrates what I'm trying to do.  Using an overloaded
  17. operator new(), I get unexpected results when using SPARCompiler, and
  18. the expected results with SGI C++.
  19.  
  20. When this program is run on the Sun, the resulting output is
  21.  
  22.   ** C++ new
  23.   A constructor
  24.   A constructor
  25.   A constructor
  26.   ** My new
  27.   A constructor
  28.  
  29. I was expecting to see three constructor messages after "My new", which
  30. is what I get on the SGI.
  31.  
  32. I've checked the Sun patch lists, but couldn't find anything that sounded
  33. relevant.
  34.  
  35. Firstly, am I correct in assuming that there should be three constructor
  36. messages?  Secondly, if I am correct, doesn't this seem like a bug in
  37. the SPARCompiler?  Is there a patch to fix this problem?
  38.  
  39. Thanks,
  40.  
  41. Mark Spruiell
  42. Lawrence Livermore National Laboratory
  43. mes@llnl.gov
  44.  
  45.  
  46. #include <iostream.h>
  47. #include <new.h>
  48.  
  49. class A
  50. {
  51. public:
  52.   A() { cout << "A constructor" << endl; }
  53. };
  54.  
  55. void* operator new(size_t size, int dummy)
  56. {
  57.   return ::operator new(size);
  58. }
  59.  
  60. int main(int, char**)
  61. {
  62.   cout << "** C++ new" << endl;
  63.   A* a1 = new A[3];
  64.  
  65.   cout << "** My new" << endl;
  66.   A* a2 = new(0) A[3];
  67.  
  68.   return 0;
  69. }
  70.